package com.example.job10redisscene;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class HyperLogLog {

    @Autowired
    private RedisTemplate redisTemplate;

    public void click() {
        String key = "randomClick";
        redisTemplate.delete(key);
        for (int i = 0; i < 1000; i++) {
            //随机点击一个数字
            redisTemplate.opsForHyperLogLog().add(key, String.valueOf(new Random(System.currentTimeMillis()).nextInt(1000)));
        }
        // 得出点击的数字的个数（去重）
        System.out.println(redisTemplate.opsForHyperLogLog().size(key)); //10
    }
}
